package view.ui 
{
	import comp.display.Label;
	import comp.display.PicContainer;
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextFormat;
	import flash.utils.ByteArray;
	import model.data.NiaoyuIdea;
	import util.ElemLib;
	
	/**
	 * ...
	 * @author Qi Donghui
	 */
	public class IdeaItem extends Sprite 
	{
		public var _bg:Sprite;
		
		private var _data:NiaoyuIdea;
		
		private var _pic:PicContainer;
		
		public function IdeaItem(data:NiaoyuIdea) 
		{
			_data = data;
		}
		
		private function renderBg():void
		{
			_bg.graphics.clear();
			_bg.graphics.lineStyle(1, 0xdadada);
			_bg.graphics.beginFill(0xfafafa);
			_bg.graphics.drawRect(0, 0, 560, this.height + 26);
			_bg.graphics.endFill();	
		}
		
		////////////////////////////////////////////////////////////
		//// 共有函数
		////////////////////////////////////////////////////////////
		public function render():void
		{
			if (_bg == null) _bg = new Sprite();
			addChild(_bg);		
			
			var t1:Label = new Label(this, 6, 10, "创意词条", new TextFormat(null, 12, null, true));
			var t2:Label = new Label(this, 6, 37, _data.content, new TextFormat(null, 12, 0x4c4c4c));
			
			renderBg();
			
			if (_data.picture != null)
			{
				_pic = new PicContainer();
				_pic.addEventListener(Event.COMPLETE, onPicRendered);
				_pic.source = _data.picture;
				_pic.x = 10;
				_pic.y = 73;
				addChild(_pic);
			}
		}
		
		private function onPicRendered(e:Event):void 
		{
			renderBg();
			dispatchEvent(new Event(Event.CHANGE));
		}
		

		
		
	}

}